<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>为按钮添加事件</title>
</head>
<body>
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button>7</button>
<button>8</button>
<button>9</button>
<button>10</button>
<script type="text/javascript">
    let buttons = document.getElementsByTagName("button");

    for (let i = 0; i < buttons.length; i++) {
        buttons[i].onclick = print; // 绑定log
        buttons[i].onmouseover = print;
        buttons[i].onmouseenter = print;
        buttons[i].onmouseout = print;
    }

    function print() {
        console.log("你" + window.event.type + "了按钮，事件为：" + window.event.target.innerHTML);
    }
</script>
</body>
</html>